#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
<<<<<<< HEAD
@File Name  : Mzitu_sort.py
@Author     : LeeCQ
@Time       : 2019/11/29 13:02

对数据库内容排序；
"""
import os, sys

sys.path.extend(os.path.dirname(os.path.abspath(__file__)))
import pymysql

from Mzitu_db import MzituDBNoJSON
from Mzitu import MzituDownload


# from Mzitu_info import MySQLInfo


class NewMzituNoJSON(MzituDBNoJSON):
    """需要创建新的数据库-重置sheet"""
    sheet_all_album = 'new_mzitu'


class SqlSort(MzituDownload):
    """对数据库内容，排序"""

    def __init__(self):
        super().__init__()
        # 创建数据库连接句柄；
        self._db = NewMzituNoJSON()
        self.new_sql = NewMzituNoJSON()
        self.old_sql = MzituDBNoJSON()  # return pymysql.connect(**kwargs)
        # self.init_sheet()

    def init_sheet(self):
        """从新获取妹子图网站的所有相册，逆序导入"""
        self.all_albums(self.URL, self.HEADERS)

    def update_sheet(self):
        """从表Mzitu读取数据更行到New_Mzitu中。"""
        idd_tags = self.new_sql.view_column(self.new_sql.sheet_all_album, 'IDD', 'TAGS')
        for idd, tags in idd_tags:
            if tags is None:
                try:
                    where = str('IDD={}'.format(str(idd)))
                    TAGS, TIME, DATA = self._db.view_column(self.old_sql.sheet_all_album, 'TAGS', 'TIME', 'DATA',
                                                            WHERE=f'idd={idd}')[0]

                    # = data[0], data[1], data[2]
                    self.new_sql.all_album_update(idd, 'TAGS', TAGS, TIME=TIME, DATA=DATA)
                except IndexError:
                    pass


if __name__ == '__main__':
    a = SqlSort()
    a.update_sheet()
=======
@Time   : 2019/11/29 13:02
@Author : LeeCQ
@File Name: Mzitu_sort.py
"""
>>>>>>> 0f663d9cdbaca672411c54e3f484639a12f0b328
